<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 困于环中的机器人 -->
    <script>
      function isRobotBounded(instructions) {
        let distance = Array(4).fill(0) // 朝四个方向行走的距离
        let direct = 0 // 当前朝向
        for (let i of instructions) {
          if (i == 'L') {
            direct = (direct - 1 + 4) % 4
            continue
          }
          if (i == 'R') {
            direct = (direct + 1) % 4
            continue
          }
          distance[direct]++
        }
        // 面朝北方且不在原点
        return !(direct == 0 && (distance[0] != distance[2] || distance[1] != distance[3]))
      }
      console.log(isRobotBounded('GGLLGG'))
    </script>
  </body>
</html>
